package com.example.ncov_management_system.service;

import com.example.ncov_management_system.dao.ClbumDao;
import com.example.ncov_management_system.entity.Clbum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static java.util.Arrays.*;

@Service
public class ClbumService {
    @Autowired
    private ClbumDao clbumDao;
    
    public List<Clbum> list() {
        return clbumDao.findAll();
    }

    
    public Clbum findByName(String name) {
        return clbumDao.findByName(name);
    }

    
    public void add(String name) {
        Clbum clbum = new Clbum();
        clbum.setName(name);
        clbumDao.save(clbum);
    }

    
    public Clbum findById(long id) {
        return clbumDao.findById(id).orElse(null);
    }

    
    public void save(Clbum clbum) {
        clbumDao.save(clbum);
    }

    
    public void deleteById(long id) {
        clbumDao.deleteById(id);
    }

    public List<Clbum> findByIds(long[] ids) {

        ArrayList<Long> list = new ArrayList<>();
        for (long id : ids) {
            list.add(id);
        }
        return clbumDao.findAllById(list);
    }
    public List<Clbum> findByTeacherIsNull() {
        return clbumDao.findByTeacherIsNull();
    }
}
